package com.zl.learning.maven.javapack2;

import com.google.gson.Gson;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.Map;

public class TestResource {

    public static void main(String[] args) throws IOException, URISyntaxException {
        URI f = ClassLoader.getSystemResource("conf/1.txt").toURI();
//        String f = "conf/1.txt";
//        String f = ClassLoader.getSystemResource("conf/1.txt").getPath();
        System.out.println(f);
        Map<String, String> map = new HashMap<>();
        map.put("a", "AAA");
        map.put("b", "BBB");
        System.out.println(map);
        Files.write(Paths.get(f), map.toString().getBytes(), StandardOpenOption.CREATE);
        System.out.println(f);
        String val = new String(Files.readAllBytes(Paths.get(f)));
        System.out.println(val);
        URI classPath = ClassLoader.getSystemResource("").toURI();
        System.out.println(classPath);
        System.out.println(Paths.get(classPath));
        String p = Paths.get(classPath).toString();
        System.out.println(p);
        Gson gson = new Gson();
        Files.write(Paths.get(p, "conf/2.json"), gson.toJson(map).getBytes(), StandardOpenOption.CREATE);
    }
}
